// Copyright 2008 Senary
// See credits.txt for details.

// This file is part of Omega VII.

// Omega VII is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.

// Omega VII is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with Omega VII.  If not, see <http://www.gnu.org/licenses/>.

#include "MessageBoard.h"

MessageBoard::MessageBoard(void)
{
	_size = 0;
}

MessageBoard::~MessageBoard(void)
{
	
}

void MessageBoard::createMessageBoard(void)
{
	float scale = 1.0;

	_pText = txt_create(_VAR(CAPACITY), _VAR(1));
	_pText->font = font_create("system");
	//positioning
	_pText->pos_x = _VAR(10);
	_pText->pos_y = _VAR(80);
	//scaling
	_pText->scale_x = _VAR(scale);
	_pText->scale_y = _VAR(scale);
	//color
	_pText->red = _VAR(0);
	_pText->green = _VAR(255);
	_pText->blue = _VAR(0);
	//flags
	_pText->flags |= VISIBLE;
}

void MessageBoard::appendMessage(string const& message) 
{
	//normal appending message to the end
	if(_size<CAPACITY) {
		_pText->string[_size] = str_create(const_cast<char*>(message.c_str()));
		_size++;
		return;
	}

	//pop oldest msg and push new msg
	str_remove(_pText->string[0]);
	for(int i=0;i<_size-1;i++)
		_pText->string[i] = _pText->string[i+1];

	_pText->string[_size-1] = str_create(const_cast<char*>(message.c_str()));
}
